package fr.ups.jim.isi.tp1 ;

import javax.swing.*;
import java.awt.*;

import java.awt.event.ActionListener ;
import java.awt.event.ActionEvent ;
import java.awt.Container ;

/**
 * @author Nicolas Roussel (roussel@lri.fr)
 *
 */
/**
 * @author Administrator
 *
 */
public class ImpelBorderLayout extends JFrame implements ActionListener {
	
	private JLabel label1;
    private JButton button1 ;
    private JButton button2;

    //  control the layout of "widgets" by "BoderLayout"
    public ImpelBorderLayout() {
    	this.setTitle("Box #1");
    	this.setSize(400, 200);
    	label1 = new JLabel();
    	button1 = new JButton();
    	button2 = new JButton();
        button1.addActionListener(this);
	    Container pane = getContentPane();
	    BorderLayout bl = new BorderLayout();
	    pane.setLayout(bl);
        pane.add(label1, BorderLayout.CENTER);
        
        // creates a JPanel to as an embeded container to hold button1 and button2
        JPanel jp = new JPanel();
	    jp.add(button1);
        jp.add(button2);
        
        // put JPanel in "pane" container
        pane.add(jp, BorderLayout.SOUTH);
    }

    
    public ImpelBorderLayout(String title, String message, String b1lbl, String b2lbl) {
    	this() ;
    	configure(title,message,b1lbl,b2lbl) ;
    }

    
    public void configure(String title, String message, String b1lbl, String b2lbl) {
    	label1.setText(message);
    	button1.setText(b1lbl);
    	button2.setText(b2lbl);
        setVisible(true) ;
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    
    public void actionPerformed(ActionEvent e) {
    	JButton button = (JButton)e.getSource() ;
    	if (button==button1) {
    		System.out.println(button.getText()) ;
    	}
    }

    
    public static void showBox() {
    	ImpelBorderLayout box = new ImpelBorderLayout("HandmadeDialog",
									   "Vous avez fini le premier exercice...",
									   "Stop", "Encore") ;
    }

    
    static public void main(String args[]) {
    	
    	ImpelBorderLayout.showBox();
    	
    	
//    	JFrame frame = new JFrame("Box #1") ;
//    	showBox();
//    	JButton button = new JButton("showBox") ;
//    	button.addActionListener(new ActionListener() {
//    		public void actionPerformed(ActionEvent evt) { showBox() ; }
//		}) ;
//    	frame.add(button) ;
//    	frame.pack() ;
//    	frame.setVisible(true) ;
//    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
